<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Shipment extends Model
{
    protected $table = 'shipments';
    protected $fillable = [
        'client_company',
        'codeno',
        'pay',
        'pay_status',
        'client_phone',
        'jiaohuo_at',
        'status',
        'all_price',
        'all_install_price',
        'ship_nums',
        'remark'
    ];
    public function shipment_item(){
        return $this->hasMany('App\ShipmentItem');
    }
    public function scopeEnable($query){
        return $query->where('status',1);
    }
    public function scopeAllOrSearch($query,$searchQuery = null)
    {
        if (is_null($searchQuery)) {
            return $query->paginate(config('admin.shipment.perpage'));
        }else{
            $search="%{$searchQuery}%";
            return $query->where('client_company','like',$search)
                    ->orWhere('codeno', 'like', $search)
                    ->orWhere('client_phone', 'like', $search)
                    ->paginate(config('admin.shipment.perpage'));
        }
    }
}
